package com.galaxy.device.config;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "spring.influx")
public class InfluxDBConfig {

    // 从配置文件中读取 InfluxDB 的连接信息
    private String url;

    private String token;

    private String org;

    private String bucket;

    // 使用 InfluxDBClientFactory 创建客户端实例
    @Bean
    public InfluxDBClient influxDBClient() {
        System.out.println("url:" + url);
        System.out.println("token:" + token);
        System.out.println("org:" + org);
        System.out.println("bucket:" + bucket);
        return InfluxDBClientFactory.create(url, token.toCharArray(), org, bucket);
    }
}
